#ifndef _MOTASP_CFG_H_
#define _MOTASP_CFG_H_
/**
 *Copyright(C),2024, Ningbo Tuopu Group Co., Ltd.
 *FileName:   MotAsp_Cfg_I.h
 *Date:       2024-12-16 19:03:04
 *Author:     TianGui.Wang
 *Version:    0
 *Path:
 *Description:
 */
/****************************************************************************/
/*                             Include area                                 */
/****************************************************************************/
#include "MotAsp/MotAsp_Lib.h"
#include "MotAsp/MotAsp_Type.h"
/****************************************************************************/
/*                             Definition area                              */
/****************************************************************************/

/***********************************Characteristic parameters of the resolver sensor********************************************************/
#define MOTASP_CFG_MSP_SIN_I_COS_I_ENLARGE_GAIN             (5U)     /*Collect SIN- 、SIN+ and COS-、COS+ data for 5 backup detection and filtering*/
#define MOTASP_CFG_MSP_SIN_I_COS_I_SIMP_NUM                 (3U)     
#define MOTASP_CFG_MSP_SIN_COS_SIMP_NUM                     (5U)     /*Collect SIN and COS data for 5 backup detection and filtering*/
  

#define MOTASP_CFG_MSP_QUADI_BASIC                          (0U)            
#define MOTASP_CFG_MSP_QUADII_BASIC                         (16384U)      
#define MOTASP_CFG_MSP_QUADIII_BASIC                        (32768U)      
#define MOTASP_CFG_MSP_QUADIV_BASIC                         (49152U)     

#define MOTASP_CFG_MSP_DRGREES_180                          (32768U)
#define MOTASP_CFG_MSP_DRGREES_360                          (65535U)
#define MOTASP_CFG_MSP_DRGREES_90                           (16384U)

#define MOTASP_CFG_MSP_ARCTAN_NUM                           (1024U)

#define MOTASP_CFG_MSP_SINCOS_AMPLITUTE                     (16384)
/***********************************Characteristic parameters of the resolver sensor********************************************************/

/***********************************The set time or maximum number of timers and counts********************************************************/
#define MOTASP_CFG_MSP_SIN_COS_I_DIAG_CNT_TIME              (20U)     
#define MOTASP_CFG_MSP_SICO_MIN_MAX_DIAG_CNT_TIME           (255U)     
#define MOTASP_CFG_MSP_SIN_COS_CNT_TIME                     (100U)     
/***********************************The set time or maximum number of timers and counts********************************************************/

/***********************************The sampled AD value is set according to the actual sensor data collection data********************************************************/
#define MOTASP_CFG_MSP_SICO_I_AD_RAW_GND_VAL                (10U)     
#define MOTASP_CFG_MSP_SICO_I_AD_RAW_MIN_VAL                (500U)      
#define MOTASP_CFG_MSP_SICO_I_AD_RAW_MAX_VAL                (3500U)  
#define MOTASP_CFG_MSP_SICO_I_AD_RAW_VBAT_VAL               (4000U)  


#define MOTASP_CFG_MSP_AD_ENLARGE_SICO_INIT_OFFSETINIT      (0)     
#define MOTASP_CFG_MSP_AD_ENLARGE_SICO_INIT_BASICMAXINIT    (9000)     
#define MOTASP_CFG_MSP_AD_ENLARGE_SICO_INIT_BASICMININIT    (-9000)  
#define MOTASP_CFG_MSP_AD_ENLARGE_SICO_INIT_CALIB_DIFF      (50)    

#define MOTASP_CFG_MSP_AD_ENLARGE_SIN_MIN_INIT              (-10500)
#define MOTASP_CFG_MSP_AD_ENLARGE_SIN_MAX_INIT              (10500)
#define MOTASP_CFG_MSP_AD_ENLARGE_COS_MIN_INIT              (-10500)
#define MOTASP_CFG_MSP_AD_ENLARGE_COS_MAX_INIT              (11000)

#define MOTASP_CFG_MSP_AD_ENLARGE_MINMAX_CENTER_INIT        (0)        
#define MOTASP_CFG_MSP_AD_ENLARGE_MINMAX_AMPLITUTE_INIT     (10000)    
/***********************************The sampled AD value is set according to the actual sensor data collection data********************************************************/

/***********************************PI parameters related to the resolver sensor********************************************************/
#define MOTASP_CFG_MSP_PI_GAIN                              (32)
#define MOTASP_CFG_MSP_PI_MOLECULE                          (3277)                  
#define MOTASP_CFG_MSP_PI_NUMERATOR                         (4096)                              
/***********************************PI parameters related to the resolver sensor********************************************************/


#define MOTASP_CFG_MOTOR_POLES                              (6U)

/*Array of velocity filtered and computed*/
#define MOTASP_CFG_SPD_SIMP_ARR_NUM                         (10)
/*Velocity filter coefficient molecule 1*/
#define MOTASP_CFG_SPD_CALC_MOLECULE0                       (22)
/*The velocity filter coefficient denominator is 1*/                                
#define MOTASP_CFG_SPD_CALC_NUMERATOR0                      (100)   
/*Velocity filter coefficient molecule 2*/         
#define MOTASP_CFG_SPD_CALC_MOLECULE1                       (78)
/*The velocity filter coefficient denominator is 2*/                
#define MOTASP_CFG_SPD_CALC_NUMERATOR1                      (100)            

/*How many times does one minute correspond to the operating cycle cycle, which is currently 100us*/
#define MOTASP_CFG_MIN_TO_PERIOD                            (60*10000)
/*How many times does one minute correspond to the operating cycle cycle, which is currently 1ms*/
#define MOTASP_CFG_MIN_SPD_TO_PERIOD                        (60*1000)
/*The minimum velocity of the virtual angle, in RPM*/
#define MOTASP_CFG_VIRTUAL_START_SPD                        (4)

/*The maximum value of one turn of electric angle, the range is 0~65535*/
#define MOTASP_CFG_MOTOR_CYCLE_MAX_VAL                      (65535)

/*The mechanical angle of the screw lead, 1 turn, is equal to 5mm, and the unit is 0.01mm*/
#define MOTASP_CFG_MOTOR_SCREW_LEAD                         (500)

/*The voltage range of the four signals of the MPS*/
/*******************************************************************************************/
#define MOTASP_CFG_DIAG_SINCOS_ENABLE                       (MOTASP_ENABLE)

#if(MOTASP_CFG_DIAG_SINCOS_ENABLE == MOTASP_ENABLE)

#define MOTASP_CFG_DIAG_SIN0_AD_GND_VAL                     (MOTASP_CFG_MSP_SICO_I_AD_RAW_GND_VAL)     
#define MOTASP_CFG_DIAG_SIN0_AD_MIN_VAL                     (MOTASP_CFG_MSP_SICO_I_AD_RAW_MIN_VAL)     
#define MOTASP_CFG_DIAG_SIN0_AD_MAX_VAL                     (MOTASP_CFG_MSP_SICO_I_AD_RAW_MAX_VAL)   
#define MOTASP_CFG_DIAG_SIN0_AD_VBAT_VAL                    (MOTASP_CFG_MSP_SICO_I_AD_RAW_VBAT_VAL)

#define MOTASP_CFG_DIAG_SIN1_AD_GND_VAL                     (MOTASP_CFG_MSP_SICO_I_AD_RAW_GND_VAL)   
#define MOTASP_CFG_DIAG_SIN1_AD_MIN_VAL                     (MOTASP_CFG_MSP_SICO_I_AD_RAW_MIN_VAL)   
#define MOTASP_CFG_DIAG_SIN1_AD_MAX_VAL                     (MOTASP_CFG_MSP_SICO_I_AD_RAW_MAX_VAL) 
#define MOTASP_CFG_DIAG_SIN1_AD_VBAT_VAL                    (MOTASP_CFG_MSP_SICO_I_AD_RAW_VBAT_VAL)

#define MOTASP_CFG_DIAG_COS0_AD_GND_VAL                     (MOTASP_CFG_MSP_SICO_I_AD_RAW_GND_VAL)    
#define MOTASP_CFG_DIAG_COS0_AD_MIN_VAL                     (MOTASP_CFG_MSP_SICO_I_AD_RAW_MIN_VAL)    
#define MOTASP_CFG_DIAG_COS0_AD_MAX_VAL                     (MOTASP_CFG_MSP_SICO_I_AD_RAW_MAX_VAL)  
#define MOTASP_CFG_DIAG_COS0_AD_VBAT_VAL                    (MOTASP_CFG_MSP_SICO_I_AD_RAW_VBAT_VAL) 

#define MOTASP_CFG_DIAG_COS1_AD_GND_VAL                     (MOTASP_CFG_MSP_SICO_I_AD_RAW_GND_VAL)    
#define MOTASP_CFG_DIAG_COS1_AD_MIN_VAL                     (MOTASP_CFG_MSP_SICO_I_AD_RAW_MIN_VAL)    
#define MOTASP_CFG_DIAG_COS1_AD_MAX_VAL                     (MOTASP_CFG_MSP_SICO_I_AD_RAW_MAX_VAL)  
#define MOTASP_CFG_DIAG_COS1_AD_VBAT_VAL                    (MOTASP_CFG_MSP_SICO_I_AD_RAW_VBAT_VAL) 

#endif
/*******************************************************************************************/

/*******************************************************************************************/
#define MOTASP_CFG_DIAG_SINCOS_DD_ENABLE                    (MOTASP_ENABLE)

#if(MOTASP_CFG_DIAG_SINCOS_DD_ENABLE == MOTASP_ENABLE)

#define MOTASP_CFG_SICO_DEFAULT_OFFSETINIT                  (MOTASP_CFG_MSP_AD_ENLARGE_SICO_INIT_OFFSETINIT  )
#define MOTASP_CFG_SICO_DEFAULT_BASICMAXINIT                (MOTASP_CFG_MSP_AD_ENLARGE_SICO_INIT_BASICMAXINIT)
#define MOTASP_CFG_SICO_DEFAULT_BASICMININIT                (MOTASP_CFG_MSP_AD_ENLARGE_SICO_INIT_BASICMININIT)
#define MOTASP_CFG_SICO_BASICMININIT_CALIB_DIFF_V           (MOTASP_CFG_MSP_AD_ENLARGE_SICO_INIT_CALIB_DIFF  )

#endif
/*******************************************************************************************/

/*******************************************************************************************/
#define MOTASP_CFG_FILTER_SIN_GAIN                          (MOTASP_CFG_MSP_SIN_I_COS_I_ENLARGE_GAIN)
#define MOTASP_CFG_FILTER_COS_GAIN                          (MOTASP_CFG_MSP_SIN_I_COS_I_ENLARGE_GAIN)

#define MOTASP_CFG_FILTER_SIN_ARR_CNT                       (MOTASP_CFG_MSP_SIN_I_COS_I_SIMP_NUM)
#define MOTASP_CFG_FILTER_COS_ARR_CNT                       (MOTASP_CFG_MSP_SIN_I_COS_I_SIMP_NUM)
/*******************************************************************************************/


/*******************************************************************************************/
#define MOTASP_CFG_PI_MIN_SIN_GAIN                          (MOTASP_CFG_MSP_PI_GAIN)
#define MOTASP_CFG_PI_MAX_SIN_GAIN                          (MOTASP_CFG_MSP_PI_GAIN)
#define MOTASP_CFG_PI_MIN_COS_GAIN                          (MOTASP_CFG_MSP_PI_GAIN)
#define MOTASP_CFG_PI_MAX_COS_GAIN                          (MOTASP_CFG_MSP_PI_GAIN)

#define MOTASP_CFG_PI_MIN_SIN_MOLECULE                      (MOTASP_CFG_MSP_PI_MOLECULE)
#define MOTASP_CFG_PI_MAX_SIN_MOLECULE                      (MOTASP_CFG_MSP_PI_MOLECULE)
#define MOTASP_CFG_PI_MIN_COS_MOLECULE                      (MOTASP_CFG_MSP_PI_MOLECULE)
#define MOTASP_CFG_PI_MAX_COS_MOLECULE                      (MOTASP_CFG_MSP_PI_MOLECULE)

#define MOTASP_CFG_PI_MIN_SIN_NUMERATOR                     (MOTASP_CFG_MSP_PI_NUMERATOR)
#define MOTASP_CFG_PI_MAX_SIN_NUMERATOR                     (MOTASP_CFG_MSP_PI_NUMERATOR)
#define MOTASP_CFG_PI_MIN_COS_NUMERATOR                     (MOTASP_CFG_MSP_PI_NUMERATOR)
#define MOTASP_CFG_PI_MAX_COS_NUMERATOR                     (MOTASP_CFG_MSP_PI_NUMERATOR)
/*******************************************************************************************/

/*******************************************************************************************/
#define MOTASP_CFG_CALC_SIN_MIA_CNT                         (MOTASP_CFG_MSP_SIN_COS_SIMP_NUM)
#define MOTASP_CFG_CALC_COS_MIA_CNT                         (MOTASP_CFG_MSP_SIN_COS_SIMP_NUM)

#define MOTASP_CFG_CALC_SIN_MIA_RATIO                       (MOTASP_CFG_MSP_SINCOS_AMPLITUTE)
#define MOTASP_CFG_CALC_COS_MIA_RATIO                       (MOTASP_CFG_MSP_SINCOS_AMPLITUTE)

#define MOTASP_CFG_CALC_SIN_MIN_INIT                        (MOTASP_CFG_MSP_AD_ENLARGE_SIN_MIN_INIT)
#define MOTASP_CFG_CALC_SIN_MAX_INIT                        (MOTASP_CFG_MSP_AD_ENLARGE_SIN_MAX_INIT)
#define MOTASP_CFG_CALC_COS_MIN_INIT                        (MOTASP_CFG_MSP_AD_ENLARGE_COS_MIN_INIT)
#define MOTASP_CFG_CALC_COS_MAX_INIT                        (MOTASP_CFG_MSP_AD_ENLARGE_COS_MAX_INIT)
/*******************************************************************************************/

/*******************************************************************************************/
#define MOTASP_CFG_CALC_ARCTAN_ARR_NUM                      (MOTASP_CFG_MSP_ARCTAN_NUM)

#define MOTASP_CFG_CALC_ARCTAN_DEGREES_90                   (MOTASP_CFG_MSP_DRGREES_90)
/*******************************************************************************************/

/*******************************************************************************************/
#define MOTASP_CFG_CALC_ARCTAN_DEGREES_180                  (MOTASP_CFG_MSP_DRGREES_180)

#define MOTASP_CFG_CALC_ARCTAN_DEGREES_360                  (MOTASP_CFG_MSP_DRGREES_360)

/*******************************************************************************************/

/*******************************************************************************************/
#define MOTASP_CFG_CALC_SIN_MINMAX_CENTER                   (MOTASP_CFG_MSP_AD_ENLARGE_MINMAX_CENTER_INIT)
#define MOTASP_CFG_CALC_COS_MINMAX_CENTER                   (MOTASP_CFG_MSP_AD_ENLARGE_MINMAX_CENTER_INIT)
                                                                        
#define MOTASP_CFG_CALC_SIN_MINMAX_AMPLITUTE                (MOTASP_CFG_MSP_AD_ENLARGE_MINMAX_AMPLITUTE_INIT)
#define MOTASP_CFG_CALC_COS_MINMAX_AMPLITUTE                (MOTASP_CFG_MSP_AD_ENLARGE_MINMAX_AMPLITUTE_INIT)
/*******************************************************************************************/

/*******************************************************************************************/
#define MOTASP_CFG_QUADRANT_I                               (MOTASP_CFG_MSP_QUADI_BASIC)
#define MOTASP_CFG_QUADRANT_II                              (MOTASP_CFG_MSP_QUADII_BASIC)
#define MOTASP_CFG_QUADRANT_III                             (MOTASP_CFG_MSP_QUADIII_BASIC)
#define MOTASP_CFG_QUADRANT_IV                              (MOTASP_CFG_MSP_QUADIV_BASIC)
/*******************************************************************************************/


/*******************************************************************************************/
#define MOTASP_CFG_SIN0_CNT_TIME                            (MOTASP_CFG_MSP_SIN_COS_I_DIAG_CNT_TIME)
#define MOTASP_CFG_SIN1_CNT_TIME                            (MOTASP_CFG_MSP_SIN_COS_I_DIAG_CNT_TIME)
#define MOTASP_CFG_COS0_CNT_TIME                            (MOTASP_CFG_MSP_SIN_COS_I_DIAG_CNT_TIME)
#define MOTASP_CFG_COS1_CNT_TIME                            (MOTASP_CFG_MSP_SIN_COS_I_DIAG_CNT_TIME)
/*******************************************************************************************/

/*******************************************************************************************/
#define MOTASP_CFG_SIN_MIN_CNT_TIME                         (MOTASP_CFG_MSP_SICO_MIN_MAX_DIAG_CNT_TIME)
#define MOTASP_CFG_SIN_MAX_CNT_TIME                         (MOTASP_CFG_MSP_SICO_MIN_MAX_DIAG_CNT_TIME)
#define MOTASP_CFG_COS_MIN_CNT_TIME                         (MOTASP_CFG_MSP_SICO_MIN_MAX_DIAG_CNT_TIME)
#define MOTASP_CFG_COS_MAX_CNT_TIME                         (MOTASP_CFG_MSP_SICO_MIN_MAX_DIAG_CNT_TIME)
/*******************************************************************************************/

/*******************************************************************************************/
#define MOTASP_CFG_SIN_COS_CNT_TIME                         (MOTASP_CFG_MSP_SIN_COS_CNT_TIME)
/*******************************************************************************************/



/****************************************************************************/
/*                             Typedef area                                 */
/****************************************************************************/

/****************************************************************************/
/*                             Local data at RAM                            */
/****************************************************************************/

/****************************************************************************/
/*                             Global data at RAM                           */
/****************************************************************************/

/****************************************************************************/
/*                        Global data at RAM declare area                   */
/****************************************************************************/

/****************************************************************************/
/*                             Local data at ROM                            */
/****************************************************************************/

/****************************************************************************/
/*                             Global data at ROM                           */
/****************************************************************************/
/*The voltage range of the four signals of the MPS*/
extern MotAsp_Lib_SIG_V_RANGE_TYPE MotAsp_Cfg_SiCo_V_Range_Para[MotAsp_Lib_SIN_COS_SIG_NUM];

extern MotAsp_Lib_SINCOS_CALIB_PARA_STATUS MotAsp_Cfg_SiCo_Calib_Para;

extern MotAsp_Lib_SINCOS_SIMP_MID_AVG_FILTE_STAUTS MotAsp_Cfg_Sin_Filter_Para[MotAsp_Lib_SiCo_NUM];

extern MotAsp_Lib_SINCOS_CALC_CENTER_INTERIM_STATUS MotAsp_Cfg_Pi_Para[MotAsp_Lib_SIN_COS_SIG_NUM];

extern MotAsp_Lib_SINCOS_CALC_LOGIC_STATUS MotAsp_Cfg_Calc_MIA_Para[MotAsp_Lib_SiCo_NUM];

extern MotAsp_Lib_SINCOS_TRACK_COORDINATE_STATUS MotAsp_Cfg_Calc_Arctan_Para;

extern MotAsp_Lib_ANGLE_INCREMENT_STAUTS MotAsp_Cfg_Calc_Angle_Para;

extern MotAsp_Lib_SINCOS_CALC_MINMAX_ALGTH_STATUS MotAsp_Cfg_Calc_MIA_Algth_Para[MotAsp_Lib_SiCo_NUM];

extern MotAsp_Lib_COORDINATE_BASIC_ANGLE_STATE MotAsp_Cfg_Quadrant_Basic;

extern MotAsp_Lib_CNT_STATUS MotAsp_Cfg_Sin_Cos_i_Cnt_Para[MotAsp_Lib_SIN_COS_SIG_NUM];

extern MotAsp_Lib_CNT_STATUS MotAsp_Cfg_SiCo_MIN_Cnt_Para[MotAsp_Lib_SIN_COS_SIG_NUM];

extern MotAsp_Lib_CNT_STATUS MotAsp_Cfg_SiCo_Cnt_Para;


extern MotAsp_Type_VIRTUAL_CALC_STRUCT MotAsp_Cfg_Virtual;

extern MotAsp_Type_SPD_SIMPLE_STRUCT MotAsp_Cfg_Spd_Simp;

extern MotAsp_Type_SPD_CALC_STRUCT MotAsp_Cfg_Spd_Calc;

extern MotAsp_Type_ABS_POS_CALC_STRUCT MotAsp_Cfg_Abs_Pos;

extern MotAsp_Type_ABS_POS_CALC_STRUCT MotAsp_Cfg_Rel_Pos;
/****************************************************************************/
/*                        Global data at ROM declare area                   */
/****************************************************************************/

/****************************************************************************/
/*                        Local function declare area                       */
/****************************************************************************/

/****************************************************************************/
/*                        Global function declare area                      */
/****************************************************************************/

#endif
